package com.lingyi.algorithm.lab3;

import com.lingyi.algorithm.lab2.Node;

/**
 * @author chenweilong
 * @email 1433471850@qq.com
 * @date 2020-08-20 14:50
 */
public class ChainStack {


    public static void main(String[] args) {

        ChainStack chainStack = new ChainStack();
        chainStack.push(1);
        chainStack.push(2);
        chainStack.push(3);
        chainStack.print();

        System.out.println(chainStack.getPop());

        Integer pop = chainStack.pop();
        System.out.println(pop);
        chainStack.print();


    }



    private Node<Integer> node = new Node<>();

    public void push(Integer data) {
        Node<Integer> newNode = new Node<>();
        newNode.setT(data);
        newNode.setNext(node);
        node = newNode;
    }



    public Integer pop() {
        Integer ret = node.getT();
        node = node.getNext();
        return ret;
    }


    public Integer getPop() {
        return node.getT();
    }


    public void print() {
        System.out.println("当前链栈中的数据");
        Node<Integer> newNode = node;
        while (newNode != null && newNode.getNext() != null) {
            System.out.println(newNode.getT());
            newNode = newNode.getNext();
        }
    }


}
